<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
	{% load static %}
</head>
<body>
	<input type="button" value="返回上一级" onclick="location.href= '{%url 'luck:list' %}'">
	<h1>选择商品分类查看
		<form action="{% url 'luck:category_id'%}" method="get">
			{%csrf_token%}
			<select id="select_id" name="CommodityCategory">
				<option value="1">烟</option>
				<option value="2">酒</option>
			</select>
			<input type="submit" value="查看此分类商品">
		</form>
	</h1>
	
	<h1>商品总列表如下</h1>
	<ul>
		
		{% for i in all %}
			<a class="{{i.commodity_no}}"  href="{% url 'luck:commodity_no' i.commodity_no %}">
				<li>
					商品编号：<span>{{i.commodity_no}}</span>
					商品库存：<span class="stock">{{i.stock}}</span>
					商品分类：<span>{{i.category_id.category_name}}</span>
					商品名称：<span>{{i.commodity_name}}</span>
					商品图片：<span>{{i.cover}}</span>
					商品价格：<span>{{i.price}}</span>
				</li>
			</a>
			<input class="submit" type="button" value="提交订单">
			<input class="input input2" type="button" value="进行抽奖">
			<span id="is_good"></span>
		{%endfor%}
		
	</ul>
</body>
<script type="text/javascript" src="{% static 'jquery/jquery.js'%}"></script>
<script type="text/javascript">
	$('.submit').on('click',function(){
		$.ajax({
			url : "{% url 'luck:add_order'%}",
			method : 'post',
			async:false,
			data : {
				commodity_no : $('.submit').prev().attr('class'),
				csrfmiddlewaretoken: '{{ csrf_token }}'
			},
		});
		
		$('.submit').prev().children('.stock').text({{i.stock}} - 1)
	});
	

</script>
</html>